package com.zzc.service;

import com.google.gson.JsonObject;
import com.zzc.bean.DiningReceipt;
import com.zzc.bean.DiningReceipt_sum;
import com.zzc.bean.Employee;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zzc.bean.SystemSet;
import com.zzc.dao.*;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class DiningReceiptService {
	private DiningReceipt_sumDao diningReceipt_sumDao;
    private DiningReceiptDao diningReceiptDao;
    private SystemSetDao systemSetDao;
	private EmployeeDao employeeDao;
	private DiningDao diningDao;
	public void setDiningReceiptDao(DiningReceiptDao diningReceiptDao) {
		this.diningReceiptDao = diningReceiptDao;
	}
	public void setEmployeeDao(EmployeeDao employeeDao) {
		this.employeeDao = employeeDao;
	}
	public void setDiningDao(DiningDao diningDao) {
		this.diningDao = diningDao;
	}
	public void setDiningReceipt_sumDao(DiningReceipt_sumDao diningReceipt_sumDao) {
		this.diningReceipt_sumDao = diningReceipt_sumDao;
	}

    public SystemSetDao getSystemSetDao() {
        return systemSetDao;
    }

    public void setSystemSetDao(SystemSetDao systemSetDao) {
        this.systemSetDao = systemSetDao;
    }

    public void init() {
	    for (int i=0;i<=5;i++){
            diningReceiptDao.getSession().saveOrUpdate(new DiningReceipt("admin", "青山控股集团","2018-02-03 11:16:47","中餐","4","4","初始化生成"));
            diningReceiptDao.getSession().saveOrUpdate(new DiningReceipt("admin", "青山控股集团","2018-02-03 17:16:47","晚餐","2","3","初始化生成"));
            diningReceiptDao.getSession().saveOrUpdate(new DiningReceipt("admin", "青山控股集团","2018-03-04 12:16:47","中餐","5","4","初始化生成"));
            diningReceiptDao.getSession().saveOrUpdate(new DiningReceipt("admin", "青山控股集团","2018-03-04 16:16:47","中餐","2","5","初始化生成"));
            diningReceiptDao.getSession().saveOrUpdate(new DiningReceipt("admin", "瑞浦科技集团","2018-03-04 12:16:47","中餐","5","4","初始化生成"));
            diningReceiptDao.getSession().saveOrUpdate(new DiningReceipt("admin", "瑞浦科技集团","2018-03-04 16:16:47","中餐","2","5","初始化生成"));


            diningReceipt_sumDao.getSession().saveOrUpdate(new DiningReceipt_sum("admin", "青山控股集团","2018-02-03 11:16:47","中餐","4","4","初始化生成"));
            diningReceipt_sumDao.getSession().saveOrUpdate(new DiningReceipt_sum("admin", "青山控股集团","2018-02-03 17:16:47","晚餐","2","3","初始化生成"));
            diningReceipt_sumDao.getSession().saveOrUpdate(new DiningReceipt_sum("admin", "青山控股集团","2018-03-04 12:16:47","中餐","5","4","初始化生成"));
            diningReceipt_sumDao.getSession().saveOrUpdate(new DiningReceipt_sum("admin", "青山控股集团","2018-03-04 16:16:47","中餐","2","5","初始化生成"));
            diningReceipt_sumDao.getSession().saveOrUpdate(new DiningReceipt_sum("admin", "瑞浦科技集团","2018-03-04 12:16:47","中餐","5","4","初始化生成"));
            diningReceipt_sumDao.getSession().saveOrUpdate(new DiningReceipt_sum("admin", "瑞浦科技集团","2018-03-04 16:16:47","中餐","2","5","初始化生成"));
        }
	}
	private int diningReceipt_id;//就餐编号
	private String employee_account;//用户编号
	private String dining_company;//公司名称
	private String dining_time;//就餐日期
	private String dining_type;//餐别（中餐/晚餐）
	private String leadership_number;//领导餐人数
	private String employee_number;//员工餐人数
	private String note;//备注
    private static boolean isSameDate(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date1);

        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(date2);

        boolean isSameYear = cal1.get(Calendar.YEAR) == cal2
                .get(Calendar.YEAR);
        boolean isSameMonth = isSameYear
                && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH);
        boolean isSameDate = isSameMonth
                && cal1.get(Calendar.DAY_OF_MONTH) == cal2
                .get(Calendar.DAY_OF_MONTH);

        return isSameDate;
    }
    private StringBuffer error_info;
    private boolean error_flag;
	public String add() throws UnsupportedEncodingException, ParseException {
		error_info=new StringBuffer();
		error_flag=false;
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session=request.getSession();
		Employee employee= (Employee) session.getAttribute("employee");
		employee_account=employee.getEmployee_account();
//		return addByRequest(request);

        dining_company=  request.getParameter("dining_company");
        dining_time=request.getParameter("dining_time");
        System.out.println("dining_time:"+dining_time);
        dining_type=  request.getParameter("dining_type");
        leadership_number=  request.getParameter("leadership_number");
        employee_number=  request.getParameter("employee_number");
        note=  request.getParameter("note");

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat simpleDateFormat_date = new SimpleDateFormat("yyyy-MM-dd");
        //提交的就餐时间
        Date date_submit= null;
        try {
            date_submit = simpleDateFormat_date.parse(dining_time);
        } catch (ParseException e) {
            error_info.append("提交时间格式错误");
            e.printStackTrace();
            return error_info.toString();
        }
        date_submit.setHours(0);
        date_submit.setMinutes(0);
        date_submit.setSeconds(0);
        Date date_nowaday_limited=simpleDateFormat_date.parse(simpleDateFormat_date.format(new Date()));
        date_nowaday_limited.setHours(14);
        date_nowaday_limited.setMinutes(00);
        date_nowaday_limited.setSeconds(0);
        date_nowaday_limited=simpleDateFormat.parse(simpleDateFormat.format(date_nowaday_limited));//毫秒归0

        //提交时间
        Date date_now=new Date();
        Calendar calendar_now=Calendar.getInstance();
        calendar_now.setTime(date_now);
        int weekday_now=calendar_now.get(Calendar.DAY_OF_WEEK);
//		date_now=simpleDateFormat.parse("2019-05-24 18:01:00");//测试现在时间
        Calendar calendar_allowed=Calendar.getInstance();
        calendar_allowed.setTime(date_now);
        if (date_now.getTime()<date_nowaday_limited.getTime()){
            if(weekday_now==7){
                //星期六早上+2天,报星期一
                calendar_allowed.add(Calendar.DAY_OF_MONTH, 2);
            }
            else{
                calendar_allowed.add(Calendar.DAY_OF_MONTH, 1);

            }
        }
        else{
            if(weekday_now==6){
                //星期五晚上+3天,报星期一
                calendar_allowed.add(Calendar.DAY_OF_MONTH, 3);
            }
            else{
                calendar_allowed.add(Calendar.DAY_OF_MONTH, 2);
            }
        }
        Date date_allowed;
        SystemSet systemSet=systemSetDao.getSystemSet("admin");
        boolean isAdvance=systemSet.isAdvance();
        String advanceDining_string = systemSet.getAdvanceDiningDate();
        if (isAdvance&&advanceDining_string!=null) {
            date_allowed = simpleDateFormat_date.parse(advanceDining_string);
        }
        else{
            date_allowed=calendar_allowed.getTime();
            date_allowed.setHours(0);
            date_allowed.setMinutes(0);
            date_allowed.setSeconds(0);
            date_allowed=simpleDateFormat.parse(simpleDateFormat.format(date_allowed));//毫秒归0
        }

        Date date_toaday_limited=simpleDateFormat_date.parse(simpleDateFormat_date.format(new Date()));
        date_toaday_limited.setHours(0);
        date_toaday_limited.setMinutes(0);
        date_toaday_limited.setSeconds(0);
        date_toaday_limited=simpleDateFormat.parse(simpleDateFormat.format(date_toaday_limited));//毫秒归0
        Date date_lunch_limited=new Date();
        date_lunch_limited.setHours(11);
        date_lunch_limited.setMinutes(0);
        date_lunch_limited.setSeconds(0);
        date_lunch_limited=simpleDateFormat.parse(simpleDateFormat.format(date_lunch_limited));//毫秒归0
        Date date_dinner_limited=new Date();
        date_dinner_limited.setHours(16);
        date_dinner_limited.setMinutes(0);
        date_dinner_limited.setSeconds(0);
        date_dinner_limited=simpleDateFormat.parse(simpleDateFormat.format(date_dinner_limited));//毫秒归0
        //逻辑判断
        int leadership_int=Integer.parseInt(leadership_number);
        int employee_int=Integer.parseInt(employee_number);
        if(leadership_int==0&&employee_int==0){
            error_info.append("Las personas son 0. No se puede entregar.");
            error_flag=true;
        }
        else{
            if(leadership_int!=0){
                //修改自助餐厅人数
                if (date_submit.getTime()<date_toaday_limited.getTime()){
                    error_info.append("1.Cuando entrega las reservas de dirigentes (no debe ser 0): \nEl tiempo entregado debe ser después de: "+simpleDateFormat.format(date_toaday_limited)+""+"\n");
                    error_flag=true;
                }
                else if(date_submit.getTime()==date_toaday_limited.getTime()){
                    if (dining_type.equals("中餐")){
                        if (date_now.getTime()>date_lunch_limited.getTime()){
                            error_info.append("1.提交自助餐厅时(领导餐人数不为0):\n提交今天的中餐应该在"+simpleDateFormat.format(date_lunch_limited)+"之前,现在时间："+simpleDateFormat.format(date_now)+"\n");
                            error_flag=true;
                        }
                    }
                    else if (dining_type.equals("晚餐")){
                        if (date_now.getTime()>date_dinner_limited.getTime()){
                            error_info.append("1.提交自助餐厅时(领导餐人数不为0):\n提交今天的晚餐应该在"+simpleDateFormat.format(date_dinner_limited)+"之前,现在时间："+simpleDateFormat.format(date_now)+"\n");
                            error_flag=true;
                        }
                    }
                    else {
                        error_info.append("1.提交餐别类型错误");
                        error_flag=true;
                    }
                }
            }
            if(employee_int!=0){
                //修改员工餐厅人数
//    				if (date_submit.getTime()<date_nowaday_limited.getTime()){
//    					error_info.append("提交员工餐厅时(员工餐人数>0):\n提交的就餐时间不能在"+simpleDateFormat.format(date_nowaday_limited)+"之前"+"\n");
//    					error_flag=true;
//    				}
                if (date_submit.getTime()!=date_allowed.getTime()) {
                    if (isAdvance){
                        error_info.append("2.Cuando entrega las reservas de empleados (no debe ser 0):\n检测到管理员设置自定义的提交日期\n提交的 就餐日期 应该为管理员设置的:" + simpleDateFormat.format(date_allowed)+"\nEl tiempo entregado actual es: "+simpleDateFormat.format(date_submit)+"\n");
                    }
                    else {
                        error_info.append("2.Cuando entrega las reservas de empleados (no debe ser 0):\nEl tiempo entregado debe ser el día laboral siguiente:" + simpleDateFormat.format(date_allowed)+"\nEl tiempo entregado actual es: "+simpleDateFormat.format(date_submit)+"\n");
                    }
                    error_flag=true;
                }
            }
        }
        if (error_flag){
            return error_info.toString();
        }
        DiningReceipt diningReceipt=new DiningReceipt(employee_account,dining_company,dining_time,dining_type,leadership_number,employee_number,note);
        diningReceiptDao.getSession().saveOrUpdate(diningReceipt);
        return "true";
    }
	public Map<String,Object> add_autoDining() throws UnsupportedEncodingException, ParseException {
		Map<String,Object> map_return=new HashMap<>();
		error_info=new StringBuffer();
		error_flag=false;
		HttpServletRequest request = ServletActionContext.getRequest();
		String diningReceiptId_object=  request.getParameter("diningReceipt_id");
		employee_account=  request.getParameter("employee_account");
		String employee_password=  request.getParameter("employee_password");
		if(!employee_account.equals("自动报餐")){
			Employee employee = employeeDao.login(employee_account,employee_password);
			if (employee ==null|| employee.getEmployee_account().equals("")){
				error_info.append("用户验证失败");
				error_flag=true;
				map_return.put("data",error_info.toString());
				return map_return;
			}
			else{
				dining_company=  employee.getEmployee_company();
			}
		}
		else{
			dining_company=  request.getParameter("dining_company");

		}
		dining_time=request.getParameter("dining_time");
		dining_type=  request.getParameter("dining_type");
		leadership_number=  request.getParameter("leadership_number");
		employee_number=  request.getParameter("employee_number");
		note=  request.getParameter("note");

		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat simpleDateFormat_date = new SimpleDateFormat("yyyy-MM-dd");
		//提交的就餐时间
		Date date_submit= null;

		Date date_nowaday_limited=simpleDateFormat_date.parse(simpleDateFormat_date.format(new Date()));
		date_nowaday_limited.setHours(14);
		date_nowaday_limited.setMinutes(00);
		date_nowaday_limited.setSeconds(0);
		date_nowaday_limited=simpleDateFormat.parse(simpleDateFormat.format(date_nowaday_limited));//毫秒归0

		//提交时间
		Date date_now=new Date();
		Calendar calendar_now=Calendar.getInstance();
		calendar_now.setTime(date_now);
		int weekday_now=calendar_now.get(Calendar.DAY_OF_WEEK);
//		date_now=simpleDateFormat.parse("2019-05-24 18:01:00");//测试现在时间
		Calendar calendar_allowed=Calendar.getInstance();
		calendar_allowed.setTime(date_now);
		//取消两点后，报后天的餐
//		if (date_now.getTime()<date_nowaday_limited.getTime()){
			if(weekday_now==7){
				//星期六早上+2天,报星期一
				calendar_allowed.add(Calendar.DAY_OF_MONTH, 2);
			}
			else{
				calendar_allowed.add(Calendar.DAY_OF_MONTH, 1);

			}
//		}
//		else{
//			if(weekday_now==6){
//				//星期五晚上+3天,报星期一
//				calendar_allowed.add(Calendar.DAY_OF_MONTH, 3);
//			}
//			else{
//				calendar_allowed.add(Calendar.DAY_OF_MONTH, 2);
//			}
//		}
		//取消两点后，报后天的餐
		Date date_allowed;
		SystemSet systemSet=systemSetDao.getSystemSet("admin");
		boolean isAdvance=systemSet.isAdvance();
		String advanceDining_string = systemSet.getAdvanceDiningDate();
		if (isAdvance&&advanceDining_string!=null) {
			date_allowed = simpleDateFormat_date.parse(advanceDining_string);
		}
		else{
			date_allowed=calendar_allowed.getTime();
			date_allowed.setHours(0);
			date_allowed.setMinutes(0);
			date_allowed.setSeconds(0);
			date_allowed=simpleDateFormat.parse(simpleDateFormat.format(date_allowed));//毫秒归0
		}
		if(employee_account.equals("自动报餐")){
			//自动报餐自动报下一个工作日
			dining_time=simpleDateFormat_date.format(date_allowed);
			date_submit = simpleDateFormat_date.parse(dining_time);
//		date_now=date_allowed;//总是允许报餐
		}
		try {
			date_submit = simpleDateFormat_date.parse(dining_time);
		} catch (ParseException e) {
			error_info.append("提交时间格式错误");
			error_flag = true;
			e.printStackTrace();
			map_return.put("data", error_info.toString());
			return map_return;
		}
		date_submit.setHours(0);
		date_submit.setMinutes(0);
		date_submit.setSeconds(0);

		Date date_toaday_limited=simpleDateFormat_date.parse(simpleDateFormat_date.format(new Date()));
		date_toaday_limited.setHours(0);
		date_toaday_limited.setMinutes(0);
		date_toaday_limited.setSeconds(0);
		date_toaday_limited=simpleDateFormat.parse(simpleDateFormat.format(date_toaday_limited));//毫秒归0
		Date date_lunch_limited=new Date();
		date_lunch_limited.setHours(11);
		date_lunch_limited.setMinutes(0);
		date_lunch_limited.setSeconds(0);
		date_lunch_limited=simpleDateFormat.parse(simpleDateFormat.format(date_lunch_limited));//毫秒归0
		Date date_dinner_limited=new Date();
		date_dinner_limited.setHours(16);
		date_dinner_limited.setMinutes(0);
		date_dinner_limited.setSeconds(0);
		date_dinner_limited=simpleDateFormat.parse(simpleDateFormat.format(date_dinner_limited));//毫秒归0
		//逻辑判断
		int leadership_int=Integer.parseInt(leadership_number);
		int employee_int=Integer.parseInt(employee_number);
		if(leadership_int==0&&employee_int==0){
//			error_info.append("人数均为0,不能提交");
//			error_flag=true;
		}
		else{
			if(leadership_int!=0){
				//修改自助餐厅人数
				if (date_submit.getTime()<date_toaday_limited.getTime()){
					error_info.append("1.提交自助餐厅时(领导餐人数不为0):\n提交的就餐时间不能在"+simpleDateFormat.format(date_toaday_limited)+"之前"+"\n");
					error_flag=true;
				}
				else if(date_submit.getTime()==date_toaday_limited.getTime()){
					if (dining_type.equals("中餐")){
						if (date_now.getTime()>date_lunch_limited.getTime()){
							error_info.append("1.提交自助餐厅时(领导餐人数不为0):\n提交今天的中餐应该在"+simpleDateFormat.format(date_lunch_limited)+"之前,现在时间："+simpleDateFormat.format(date_now)+"\n");
							error_flag=true;
						}
					}
					else if (dining_type.equals("晚餐")){
						if (date_now.getTime()>date_dinner_limited.getTime()){
							error_info.append("1.提交自助餐厅时(领导餐人数不为0):\n提交今天的晚餐应该在"+simpleDateFormat.format(date_dinner_limited)+"之前,现在时间："+simpleDateFormat.format(date_now)+"\n");
							error_flag=true;
						}
					}
					else {
						error_info.append("1.提交餐别类型错误");
						error_flag=true;
					}
				}
			}
			if(employee_int!=0){
				//修改员工餐厅人数
//    				if (date_submit.getTime()<date_nowaday_limited.getTime()){
//    					error_info.append("提交员工餐厅时(员工餐人数>0):\n提交的就餐时间不能在"+simpleDateFormat.format(date_nowaday_limited)+"之前"+"\n");
//    					error_flag=true;
//    				}
				if (date_submit.getTime()!=date_allowed.getTime()) {
					if (isAdvance){
						error_info.append("2.提交员工餐厅时(员工餐人数不为0):\n检测到管理员设置自定义的提交日期\n提交的 就餐日期 应该为管理员设置的:" + simpleDateFormat.format(date_allowed)+"\n当前提交的就餐时间:"+simpleDateFormat.format(date_submit)+"\n");
					}
					else {
						error_info.append("2.提交员工餐厅时(员工餐人数不为0):\n提交的 就餐日期 应该为下一个工作日:" + simpleDateFormat.format(date_allowed)+"\n当前提交的就餐时间:"+simpleDateFormat.format(date_submit)+"\n");
					}
					error_flag=true;
				}
			}
		}
		if (error_flag){
			map_return.put("data",error_info.toString());
			return map_return;
		}
		boolean isAddSave=false;
		DiningReceipt diningReceipt=null;
		if (diningReceiptId_object!=null&&Integer.parseInt(diningReceiptId_object)!=-1){
			int diningReceiptId=Integer.parseInt(diningReceiptId_object);
			if(diningReceiptId!=-1){
				diningReceipt=diningReceiptDao.get_id(diningReceiptId);
				if(diningReceipt==null){
					diningReceipt=new DiningReceipt();
					diningReceipt.setDining_id(diningReceiptId);
					isAddSave=true;
				}
			}
		}
		if(diningReceipt==null){
			diningReceipt=new DiningReceipt();
		}
		diningReceipt.setEmployee_account(employee_account);
		diningReceipt.setDining_company(dining_company);
		diningReceipt.setDining_time(dining_time);
		diningReceipt.setDining_type(dining_type);
		diningReceipt.setLeadership_number(leadership_number);
		diningReceipt.setEmployee_number(employee_number);
		diningReceipt.setNote(note);
		if(isAddSave){
			diningReceiptDao.getSession().save(diningReceipt);
		}
		else{
			diningReceiptDao.getSession().saveOrUpdate(diningReceipt);

		}
		map_return.put("data","true");
		map_return.put("diningReceipt_id",diningReceipt.getDining_id());
		return map_return;
	}
	public JsonObject get_autoDiningLimitedDate() throws ParseException {
		JsonObject jsonObject=new JsonObject();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat simpleDateFormat_date = new SimpleDateFormat("yyyy-MM-dd");
		Date date_now=new Date();
//		date_now=simpleDateFormat.parse("2021-03-21 18:01:00");//测试现在时间

		Calendar calendar_now=Calendar.getInstance();
		calendar_now.setTime(date_now);
		int weekday_now=calendar_now.get(Calendar.DAY_OF_WEEK);
		Date date_nowaday_limited=simpleDateFormat_date.parse(simpleDateFormat_date.format(new Date()));
		date_nowaday_limited.setHours(14);
		date_nowaday_limited.setMinutes(00);
		date_nowaday_limited.setSeconds(0);
		date_nowaday_limited=simpleDateFormat.parse(simpleDateFormat.format(date_nowaday_limited));//毫秒归0
		Calendar calendar_allowed=Calendar.getInstance();
		calendar_allowed.setTime(date_now);
//		if (date_now.getTime()<date_nowaday_limited.getTime()){
			if(weekday_now==7){
				//星期六早上+2天,报星期一
				calendar_allowed.add(Calendar.DAY_OF_MONTH, 2);
			}
			else{
				calendar_allowed.add(Calendar.DAY_OF_MONTH, 1);

			}
//		}
//		else{
//			if(weekday_now==6){
//				//星期五晚上+3天,报星期一
//				calendar_allowed.add(Calendar.DAY_OF_MONTH, 3);
//			}
//			else{
//				calendar_allowed.add(Calendar.DAY_OF_MONTH, 2);
//			}
//		}
		Calendar calendar_allowed_signDate=Calendar.getInstance();
		calendar_allowed_signDate.setTime(date_now);
		if(weekday_now==2){
			//星期一，取星期六的签到数据
			calendar_allowed_signDate.add(Calendar.DAY_OF_MONTH, -2);
		}
		else if(weekday_now==1){
			//星期日，取星期六的签到数据
			calendar_allowed_signDate.add(Calendar.DAY_OF_MONTH, -1);
		}
//		else{
//			//星期日,2-6，取前一天的签到数据
//			calendar_allowed_signDate.add(Calendar.DAY_OF_MONTH, -1);
//		}
		Date signDate_allowed;
		Date date_allowed;
		SystemSet systemSet=systemSetDao.getSystemSet("admin");
		boolean isAdvance=systemSet.isAdvance();
		String signDate_string = systemSet.getSignDate();
		String advanceDining_string = systemSet.getAdvanceDiningDate();
		if (isAdvance&&advanceDining_string!=null) {
			date_allowed = simpleDateFormat_date.parse(advanceDining_string);
		}
		else{
			date_allowed=calendar_allowed.getTime();
			date_allowed.setHours(0);
			date_allowed.setMinutes(0);
			date_allowed.setSeconds(0);
			date_allowed=simpleDateFormat.parse(simpleDateFormat.format(date_allowed));//毫秒归0
		}
		if (isAdvance&&signDate_string!=null) {
			signDate_allowed = simpleDateFormat_date.parse(signDate_string);
		}
		else{
			signDate_allowed=calendar_allowed_signDate.getTime();
			signDate_allowed.setHours(0);
			signDate_allowed.setMinutes(0);
			signDate_allowed.setSeconds(0);
			signDate_allowed=simpleDateFormat.parse(simpleDateFormat.format(signDate_allowed));//毫秒归0
		}
		jsonObject.addProperty("isAdvance",isAdvance);
		jsonObject.addProperty("signDate_time",simpleDateFormat_date.format(signDate_allowed));
		jsonObject.addProperty("advanceDining_time",simpleDateFormat_date.format(date_allowed));
		return jsonObject;
	}
	public void addSCs(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String scs_json=request.getParameter("scs_json");
		List<DiningReceipt> list_diningReceipt =new Gson().fromJson(scs_json,new TypeToken<List<DiningReceipt>>() {}.getType());
		for (DiningReceipt diningReceipt : list_diningReceipt){
			diningReceiptDao.getSession().saveOrUpdate(diningReceipt);
		}
	}
	public void delete(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String string_diningReceipt_id=request.getParameter("diningReceipt_id");
		if (employee_account==null||employee_account.equals("")){
			System.out.println("employee_account:null");
		}
		else {
			int diningReceipt_id= Integer.parseInt(string_diningReceipt_id);
			DiningReceipt diningReceipt = new DiningReceipt();
			diningReceipt.setDining_id(diningReceipt_id);
			diningReceiptDao.getSession().delete(diningReceipt);
		}
	}
	public void deleteAllSC_studentName(String studentName){
		List<DiningReceipt> list_diningReceipts = diningReceiptDao.getSCs_studentName(studentName);
		for (DiningReceipt diningReceipt : list_diningReceipts) {
			diningReceiptDao.getSession().delete(diningReceipt);
		}
	}
	public void alter() throws UnsupportedEncodingException {
		HttpServletRequest request = ServletActionContext.getRequest();
		diningReceipt_id= Integer.parseInt(request.getParameter("diningReceipt_id"));
		DiningReceipt diningReceipt_alter = (DiningReceipt)diningReceiptDao.getSession().get(DiningReceipt.class, diningReceipt_id);
		dining_time=  request.getParameter("dining_time");
		dining_type=  request.getParameter("dining_type");
		leadership_number=  request.getParameter("leadership_number");
		employee_number=  request.getParameter("employee_number");
		note=  request.getParameter("note");
		diningReceipt_alter.setDining_time(dining_time);
		diningReceipt_alter.setDining_type(dining_type);
		diningReceipt_alter.setLeadership_number(leadership_number);
		diningReceipt_alter.setEmployee_number(employee_number);
		diningReceipt_alter.setNote(note);
	}
	public List<DiningReceipt> getSCs_studentName(String studentName){
		return diningReceiptDao.getSCs_studentName(studentName);
	}
	public List<DiningReceipt> getSCs_courseName(String courseName){
		return diningReceiptDao.getSCs_courseName(courseName);
	}
	public List<?> getAll(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String string_timeStamp_filter=request.getParameter("timeStamp_filter");
		return diningReceiptDao.getAll(string_timeStamp_filter);
	}

	public List<DiningReceipt> get_employee_id() {
		return diningReceiptDao.get_employee_id();
	}
	public List<?> get_employee_account(String employee_account) {
		return diningReceiptDao.get_employee_account(employee_account);
	}
	public DiningReceipt alter_get_id() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String string_diningReceipt_id=request.getParameter("diningReceipt_id");
		DiningReceipt diningReceipt=new DiningReceipt();
		if (string_diningReceipt_id==null||string_diningReceipt_id.equals("")){
			System.out.println("diningReceipt_id:null");
		}
		else {
			int diningReceipt_id=Integer.parseInt(string_diningReceipt_id);
//			diningReceipt=diningReceiptDao.alter_get_id(diningReceipt_id);
			diningReceipt= (DiningReceipt) diningReceiptDao.getSession().get(DiningReceipt.class,diningReceipt_id);
		}
		return diningReceipt;
	}
}
